<?php
ob_start();
session_start();
include "checksession.php";
date_default_timezone_set('Asia/Bangkok');
include("../connect.php");
$strSearch = $_GET['show_arti_topic'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
	  <link href="../images/it_service_logo.png" rel="shortcut icon" type="image/x-icon" />
      <link rel="stylesheet" href="../css/style.css"/>
	  <script language="javascript" src="../js/jquery/jquery-1.7.1.min"></script>
	  <script type="text/javascript" src="../fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
	  <script type="text/javascript" src="../fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	  <link rel="stylesheet" type="text/css" href="../fancybox/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
 	  <link rel="stylesheet" href="../fancybox/style.css" />
	  <script type="text/javascript" src="autocomplete.js"></script>
	  <link rel="stylesheet" href="autocomplete.css"  type="text/css"/>
	  <script type="text/javascript">
		$('#form input').keydown(function(e) {
			if (e.keyCode == 13) {
				$('#myForm').submit();
			}
		});
		</script> 
	  <script type="text/javascript"> 
		$(function(){
			var objSet="#show_arti_topic";
			var objSetText="ค้นหา รหัส,ชื่อ";
			if($(objSet).val()==""){
					$(objSet).val(objSetText);
			}	
			$(objSet).focus(function(){
				if($(objSet).val()==objSetText){
						$(objSet).val("");
				}	
			}).blur(function(){
				if($(objSet).val()==""){
						$(objSet).val(objSetText);
				}	
			});
		});
	   </script>
	  <script type="text/javascript">

		$(document).ready(function() {
		
			$("#recordadd").fancybox({
				'width'				: '90%',
				'height'			: '90%',
				'autoScale'			: true,
				'scrolling'		    : 'auto',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'overlayColor'		: '#000',
				'hideOnOverlayClick': false,
				onCleanup   : function() {
                return window.location.reload();
					 }
			});

			$('a[id^="edit"]').fancybox({
				'width'				: '100%',
				'height'			: '100%',
				'autoScale'     	: true,
				'scrolling'		    : 'auto',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'overlayColor'		: '#000',
				'hideOnOverlayClick': false,
				onClosed	:	function() {
					parent.location.reload(true); 
					  }
			});

			$('a[id^="delete"]').fancybox({
				'width'				: '20%',
				'height'			: '20%',
				onStart		:	function() {
					return window.confirm('คุณต้องการลบรายการนี้ไหม?');
				},
				onClosed	:	function() {
					parent.location.reload(true); 
					  }
			});

		});
	</script>

    </head>
    <body> 
        <body class="body">
            <table align="center" width="90%">
                <tr>
                    <td colspan="2" class="header" >
                      <img src="../images/logo.png"> <img src="../images/it_service_text.png" width ="150">
                        <hr/>
                    </td>
                </tr >
                <tr  valign="top">
                    <td class="left">
                        <?php include_once "left.php"; ?>
                    </td>
                    <td>
                        <div align="right">
						<form id="myForm" name="myForm" method="get" action="<?= $_SERVER['SCRIPT_NAME']; ?>">
						<input name="show_arti_topic" type="text" id="show_arti_topic" value="<?= $_GET['show_arti_topic'];?>" />
						<input name="h_arti_id" type="hidden" id="h_arti_id" value="" />
						<input type="hidden" name="hidOK">
						 <input type="image" name="search" id="search" value="submit" src="../images/search.png" OnClick="document.all.hidOK.value = 'submit';" alt="เข้าสู่ระบบ">

				<!--		<a class="searchperson" id="searchperson" href="search_recordPerson.php"><img alt="searchperson" src="../images/search.png"/></a> -->
						</form>
						

						 <script type="text/javascript">
								function make_autocom(autoObj,showObj){
									var mkAutoObj=autoObj; 
									var mkSerValObj=showObj; 
									new Autocomplete(mkAutoObj, function() {
										this.setValue = function(id) {		
											document.getElementById(mkSerValObj).value = id;
										}
										if ( this.isModified )
											this.setValue("");
										if ( this.value.length < 1 && this.isNotClick ) 
											return ;	
										return "autocomplete_data.php?q=" +encodeURIComponent(this.value);
									});	
								}	
								 
								// การใช้งาน
								// make_autocom(" id ของ input ตัวที่ต้องการกำหนด "," id ของ input ตัวที่ต้องการรับค่า");
								make_autocom("show_arti_topic","h_arti_id");
								</script>
                         
							<a id="recordadd" href="recordadd.php"><img alt="recordadd" src="../images/recordadd.png" width="45px" /></a>
                        </div>
					</div>

                        <?
					if ($_GET["txtKeyword"] == "") {
								
						
                        $strSQL = "SELECT * FROM employee INNER JOIN mail ON employee.emp_id = mail.emp_id INNER JOIN depart ON depart.id = employee.de_id WHERE (employee.emp_id LIKE '%$strSearch%' or employee.emp_nameEng LIKE '%$strSearch%' or employee.emp_nameTh LIKE '%$strSearch%') and employee.status = 'Y' ";
                        $objQuery = mysql_query($strSQL) or die("Error Query [" . $strSQL . "]");
                        $Num_Rows = mysql_num_rows($objQuery);
						
						 if($Num_Rows == 0){
						echo "	<script language='javascript'>
								alert('ไม่มีข้อมูล');
								</script>";
								exit();
						}else{
                        $n = 1;
                        $Per_Page = 7;   // Per Page

                        $Page = $_GET["Page"];
                        if (!$_GET["Page"]) {
                            $Page = 1;
                        }

                        $Prev_Page = $Page - 1;
                        $Next_Page = $Page + 1;

                        $Page_Start = (($Per_Page * $Page) - $Per_Page);
                        if ($Num_Rows <= $Per_Page) {
                            $Num_Pages = 1;
                        } else if (($Num_Rows % $Per_Page) == 0) {
                            $Num_Pages = ($Num_Rows / $Per_Page);
                        } else {
                            $Num_Pages = ($Num_Rows / $Per_Page) + 1;
                            $Num_Pages = (int) $Num_Pages;
                        }

                        $strSQL .=" order  by employee.emp_id asc LIMIT $Page_Start , $Per_Page";
                        $objQuery = mysql_query($strSQL);
						}
                        ?>
                        <div class="nameTitle">ใบทะเบียนประวัติเจ้าหน้าที่</div>
                        <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                             <thead>
                            <tr>
                                <th width="5%">ลำดับ</th>
                                <th width="10%">รหัสพนักงาน</th>
                                <th width="10%">ชื่อ</th>
                                <th width="15%">นามสกุล</th>
                                <th width="15%">แผนก</th>
								<th width="10%">เมลล์ภายใน</th>
                                <th width="10%">เริ่มงานวันที่</th>
                                <th width="5%">แก้ไข</th>
                                <th width="5%">ลบ</th>
								<th width="5%">เอกสาร</th>

                            </tr>
                             </thead>
<?
$n = 1;
if($Page > 1)
{
	$n = ($Per_Page * ($Page-1)) + 1; 
}
while ($objResult = mysql_fetch_array($objQuery)) {
    ?>
                             <tbody>
                                <tr>

                                    <td><div align="center"><?php echo $n++; ?></div></td>
                                    <td><?= $objResult["emp_id"]; ?></td>
                                    <td><?= $objResult["emp_nameTh"]; ?></td>
                                    <td><?= $objResult["emp_surnameTh"]; ?></td>
                                    <td><?= $objResult["departname"]; ?></td>
									<td><?= $objResult["mail_local"]; ?></td>
                                    <td><?= $objResult["emp_startDate"]; ?></td>

                                    <td> <a id="edit<?=$i;?>" class="various iframe" href="editrecordform.php?emp_id=<?=$objResult["emp_id"];?>">
                                    <img src="../images/write.png" width="35px" ></a></td>

                                    <td align="center">
									<a id="delete<?=$i;?>" class="various iframe" href="deleterecordform.php?emp_id=<?=$objResult["emp_id"];?>">
                                    <img src="../images/deletered.png" width="35px" ></a></td>

									<td align="center">
									<a href="report_recordperson.php?emp_id=<?=$objResult["emp_id"];?>" target="_blank">
                                    <img src="../images/pdf.png" width="35px" ></a></td>
									</tr>
    <?
		$n++;
}
?>
                                  </tbody>
                        </table>
                         <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                             <tr>
                                 <td>
                             <br>
                            Total <?= $Num_Rows; ?> Record : <?= $Num_Pages; ?> Page :
                            <?
                            if ($Prev_Page) {
                                echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&show_arti_topic=$_GET[show_arti_topic]'><< Back</a> ";
                            }

                            for ($i = 1; $i <= $Num_Pages; $i++) {
                                if ($i != $Page) {
                                    echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&show_arti_topic=$_GET[show_arti_topic]'>$i</a> ]";
                                } else {
                                    echo "<b> $i </b>";
                                }
                            }
                            if ($Page != $Num_Pages) {
                                echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&show_arti_topic=$_GET[show_arti_topic]'>Next>></a> ";
                            }
						}
                            ?>
                                 </td>
                             </tr>
                         </table>
                    </td>
                </tr>  
                <tr>
                    <td colspan="2">
                        <div><a href="../checklogout.php" onclick="return confirm('what do you want Exit')"> <img src="../images/logout.png" width="150px"></img></a></div>
                    </td>
                </tr>
                <tr>
                    <td class="footer" colspan="2">
                        Powered by Department Technology information Adinop
                    </td>
                </tr>
            </table>
        </body>
</html>